<?php
/* echo "8;";
require_once ("../config.inc.php");
require_once ("../include/mysql.inc.php");


$linkDao = new Link();


$result =$linkDao->query();
if (mysql_num_rows ( $result ) > 0) {
	echo "<table >";
	while ( $row = mysql_fetch_object ( $result ) ) {
		echo "<tr>";
		echo "<td>" . $row->name . "</td>";
		//echo "<td>" . $row->password . "</td>";
		//echo "<td>" . $row->name . "</td>";
	}
	echo "</table >";
} else {
	echo "未找到";
} */

class Link extends Mysql {
	public function __construct() {
		parent::__construct();
	}
	/**
	 * 得到所有link
	 * 2012-5-2 上午10:49:26
	 * Xewee.Zhiwei.Wang
	 */
	public function query() {
		$sql = "select * from link order by sort asc;";
		$rows = $this->exec_query($sql);
		
		return $rows;
		
	}
	public function querybyid($id) {
		$sql = "select * from link where link.id= $id;";
		$rows = $this->exec_query($sql);
	
		if ($rows && count($rows) > 0) {//返回第一篇文章
			return $rows[0];
		}
		return $rows[0];
		
	}
	/**
	 * 添加link
	 * 2012-5-2 下午3:54:55
	 * Xewee.Zhiwei.Wang
	 */
	public function add($id, $name, $link, $num) {
		$sql = "insert into link(name, link, num) values ('$name', '$link', $num)";
		return $this->exec_update($sql);
	}
	/**
	 * 删除link
	 * 2012-5-2 下午3:54:58
	 * Xewee.Zhiwei.Wang
	 */
	public function delete($id) {
		$sql = "delete from link where id = $id";
		return $this->exec_update($sql);
	}
	/**
	 * 更新link
	 * 2012-5-2 下午3:55:00
	 * Xewee.Zhiwei.Wang
	 */
	public function update($id, $name, $link, $num) {
		$sql = "update link set name = '$name', link = '$link', num = $num where id = $id";
		return $this->exec_update($sql);
	}
}

?>
